<script type="text/javascript" src="../static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../static/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="../static/ueditor/lang/zh-cn/zh-cn.js"></script>
<link type="text/css" href="../static/ueditor/themes/default/css/ueditor.css" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="../static/Huploadify-master/Huploadify.css">
<script type="text/javascript" src="../static/Huploadify-master/jquery.Huploadify.js"></script>
<script type="text/javascript">
    var webParam = new Object();
    //获取-WEB页面传递参数
    function setWebParam_showWin() {
        //获取URL中问号后面的部分，并去掉问号
        var paramsUrl = "";
        var params = (decodeURI(location.search)).substr(1);
        var paramsArr = params.split("&");
        for (var i = 0; i < paramsArr.length; i++) {
            if(paramsArr[i].split("=")[0]=="url"){
                paramsUrl = unescape(paramsArr[i].split("=")[1]);
                break;
            }
        }

        paramsUrl = paramsUrl.substr(paramsUrl.indexOf('?')+1);
        var objArr = paramsUrl.split("&");
        var s = new Object();
        for (var i = 0; i < objArr.length; i++) {
            s[objArr[i].split("=")[0]] = unescape(objArr[i].split("=")[1]);
        }
        webParam = s;
    }

    $(function() {
        setWebParam_showWin();
        if (webParam.batch != undefined && webParam.batch != '' && webParam.batch != null) {
            $("#batch").val(webParam.batch);
            //判断-是否进行批量同步
            if(webParam.batch=='1'){
                $("#valDiv01").hide();
                $("#valDiv02").show();
            }else{
                $("#valDiv01").show();
                $("#valDiv02").hide();
            }
        }else{
            $("#valDiv01").hide();
            $("#valDiv01").html("");
            $("#valDiv02").hide();
            $("#valDiv02").html("");
        }
    });

    //保存_按钮事件
    $("#btnSave").click(function () {
        //判断-是否进行批量同步
        if(webParam.batch=='1'){
            //内容验证
            if(undefined == $("#fileUrl").val() || $("#fileUrl").val() == null || $("#fileUrl").val() == '') {
                j_tip("请上转文件","error");
                return;
            }
        }else{
            //内容验证
            if(undefined == $("#code").val() || $("#code").val() == null || $("#code").val() == ''){
                addError($("#code"),"请填写总公司金融代码.");
                return;
            }else if(undefined == $("#tenantPass").val() || $("#tenantPass").val() == null || $("#tenantPass").val() == ''){
                addError($("#tenantPass"),"请填写金融密码.");
                return;
            }
        }

        $("#btnSave").blur();
        showLoading();

        fy_api.ajaxSubmit($("#saveForm"),{
            success: function (data) {
                hideLoading();
                if (!data.code == 100) {
                    $.messager.alert('系统提示', data.msg, 'error', function () { self.focus(); });
                } else {
                    $.messager.alert('系统提示', data.msg, 'debug', function () { self.focus(); });
                    parent.grid_get("grid").datagrid("load");
                    turnBack();
                }
            }
        });

    });

    //上传_按钮事件
    $("#btnUpload").click(function () {
        //内容验证
        var xf = $("#xlsFile");
        if(undefined == xf.val() || xf.val()==null || xf.val()==""){
            j_tip("请选择文件","error");
            return;
        }
        var xf_ss = xf.val();
        xf_ss = xf_ss.substr(xf_ss.indexOf('.'));
        if(xf_ss!='.xls' && xf_ss!='.xlsx' ){
            j_tip("文件格式限制为(.xls .xlsx)","error");
            return;
        }

        $("#btnUpload").blur();
        showLoading();

        var formData = new FormData(document.getElementById("uploadForm"));
        fy_api.ajax({
            type:"POST",
            url: "company/upload.do",
            processData:false,
            contentType:false,
            data : formData,
            success: function(data){
                hideLoading();
                if (!isSuccess(data)) {
                    $.messager.alert('系统提示', data.msg, 'error', function () {/* self.focus(); */});
                }else{
                    $("#fileUrl").val(data.content);
                }
            }
        });

    });

    //返回_按钮事件
    function turnBack() {
        parent.j_closeWin();
    }
</script>
<div id="valDiv01">
    <form action="company/synchroCompany.do" method="post" id="saveForm">
        <input type="hidden" name="batch" id="batch" value="0" />
        <input type="hidden" name="fileUrl" id="fileUrl" value="" />
        <table style="margin: 10px auto;border: 1px solid darkgrey;padding: 10px">
            <tr>
                <td>
                    <div class="div-label">总公司金融代码：</div>
                </td>
                <td>
                    <div class="div-item">
                        <input type="text" id="code" name="code" value="" />
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="div-label">金融密码：</div>
                </td>
                <td>
                    <div class="div-item">
                        <input type="text" id="tenantPass" name="tenantPass" value="" />
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="valDiv02">
    <form action="company/upload.do" method="post" enctype="multipart/form-data" id="uploadForm">
        <table style="margin: 10px auto;border: 1px solid darkgrey;padding: 10px">
            <tr>
                <td>
                    <div class="div-label">选择文件：</div>
                </td>
                <td>
                    <div class="div-item">
                        <input type="file" accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" id="xlsFile" name="xlsFile">&nbsp;&nbsp;
                        <a id="btnUpload" class="easyui-linkbutton">上传</a>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>
<div class="form-buttons">
    <a id="btnSave" class="easyui-linkbutton" iconCls="icon-save">同步</a>
    <a id="btnBack" class="easyui-linkbutton c2" iconCls="icon-undo" onClick="turnBack();">返回</a>
</div>